package day18.tarena.Thred;
public class Back implements Runnable{
	private int count = 2000;
	Object obj = new Object();
	public void run() {
		synchronized (this) {			//同步机制，
			int temp = count;
			temp = temp - 800;
			try {
				Thread.sleep(1000); // 模拟网络的延时
			} catch (Exception e) {
				e.printStackTrace();
			}
			count = temp;
			// 将取钱后的余额，写回数据中心
		}
	}
	public static void main(String[] args) throws Exception{
		Back a = new Back();
		Thread t1 = new Thread(a);
		Thread t2 = new Thread(a);
		t1.start();
		t2.start();
		Thread.sleep(3000);
		System.out.println(a.count);
	}
}